package com.dingding.service.account.core.special.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.daox.IBaseDaoX;
import com.dingding.common.core.base.daox.ISQLBaseDao;
import com.dingding.common.core.beans.special.SpecialDepositAccount;
import com.dingding.common.core.beans.special.Specialdepositrecord;
import com.dingding.common.core.beans.special.Specialuseraccount;
import com.dingding.facade.account.common.dto.special.ResGetSpecialDepositAccount;
import com.dingding.facade.account.common.dto.special.ResSUAStatus;
import com.dingding.service.account.core.special.dao.ISpecialUserAccountDao;
import com.dingding.service.account.core.special.sql.SpecialDepositAccountSQL;
import com.dingding.service.account.core.special.sql.SpecialUserAccountSQL;

/**
 * 
 * @ClassName: SpecialUserAccountDaoImpl 
 * @Description: 专车用户账户DAO实现类
 * @author YHQ
 * @date 2016年12月21日 上午10:56:56
 * @since V2.5.8
 * 
 */
@Component("specialUserAccountDao")
public class SpecialUserAccountDaoImpl implements ISpecialUserAccountDao{

	private Logger log = Logger.getLogger(this.getClass());
	
	@Resource(name = "SQLBaseDao")
	private ISQLBaseDao sqlBaseDao;
	
	@Resource(name = "baseDaoX")
	private IBaseDaoX baseDaoX;
	
	/**
	 * 
	 * @Title: getSpecialUserAuthenticationStatus 
	 * @Description: 获取专车用户提现认证状态
	 * @param userId 用户Id
	 * @author YHQ 
	 * @since V2.5.8
	 * @return ResSUAStatus 获取专车用户认证状态响应Bean
	 * 
	 */
	@Override
	@Transactional(readOnly = true)
	public ResSUAStatus getSpecialUserAuthenticationStatus(String userId) {
		
		try {
			return sqlBaseDao.sqlToCustomBeanUnique(ResSUAStatus.class, SpecialUserAccountSQL.GET_SPECIAL_USER_ACCOUNT_AUTHENTICATION_STATUS, userId);
		} catch (Exception e) {
			log.error("获取专车用户提现认证状态时出现异常  类：" + this.getClass() + " getSpecialUserAuthenticationStatus()",e);
		}
		
		return null;
	}

	/**
	 * 
	 * @Title: addDepositAccount 
	 * @Description: 根据专车用户id添加专车用户提现账户
	 * @param specialDepositAccount 用户提现账户信息
	 * @author YHQ 
	 * @since V2.5.8
	 * @return boolean    返回类型
	 * 
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean addSpecialDepositAccount(SpecialDepositAccount specialDepositAccount) {
		
		try {
			baseDaoX.save(specialDepositAccount);
			return true;
		} catch (Exception e) {
			log.error("根据专车用户id添加专车用户提现账户时出现异常   类：" + this.getClass() + " addSpecialDepositAccount()", e);
		}
		
		return false;
	}

	/**
	 * 
	 * @Title: deleteSpecialDepositAccount 
	 * @Description: 根据专车用户id删除提现账户
	 * @param depositAccountId 提现账户Id
	 * @param userId 用户Id
	 * @author YHQ 
	 * @since V2.5.8 
	 * @return boolean    返回类型
	 * 
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean deleteSpecialDepositAccount(Integer depositAccountId,String userId) {
		
		try {
			return sqlBaseDao.updateSqLRow(SpecialDepositAccountSQL.DELETE_SPECIAL_DEPOSIT_ACCOUNT,depositAccountId, userId);
		} catch (Exception e) {
			log.error("根据用户id删除提现账户时出现异常   类：" + this.getClass() + " deleteDepositAccount()", e);
		}
		
		return false;
	}

	/**
	 * 
	 * @Title: getSpecialDepositAccountList 
	 * @Description: 根据专车用户id获取提现账户列表
	 * @param userId 用户Id
	 * @author YHQ 
	 * @since V2.5.8
	 * @return List<ResGetSpecialDepositAccount>    返回类型
	 * 
	 */
	@Override
	@Transactional(readOnly = true)
	public List<ResGetSpecialDepositAccount> getSpecialDepositAccountList(String userId) {
		
		try {
			return sqlBaseDao.listSqlToCustomBean(ResGetSpecialDepositAccount.class, SpecialDepositAccountSQL.GET_SPECIAL_DEPOSIT_ACCOUNT_LIST, userId);
		} catch (Exception e) {
			log.error("根据用户id获取提现账户列表时出现异常   类：" + this.getClass() + " getDepositAccountList()", e);
		}
		
		return null;
	}

	/**
	 * 
	 * @Title: updateSpecialUserAccount 
	 * @Description: 修改专车用户账户信息
	 * @param specialuseraccount 用户账户信息
	 * @author YHQ 
	 * @since V2.6.3
	 * @return boolean    返回类型
	 * 
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean updateSpecialUserAccount(Specialuseraccount specialuseraccount) {
		
		try {
			baseDaoX.update(specialuseraccount);
		} catch (Exception e) {
			log.error("修改专车用户账户信息时出现异常   类： " + this.getClass() + " updateSpecialUserAccount()", e);
		}
		
		return false;
	}

	/**
	 * 
	 * @Title: getSpecialUserAccount 
	 * @Description: 获取专车用户账户信息
	 * @param userId 用户Id
	 * @author YHQ 
	 * @since V2.6.3
	 * @return Specialuseraccount    返回类型
	 * 
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public Specialuseraccount getSpecialUserAccount(String userId) {
		
		try {
			return sqlBaseDao.sqlToCustomBeanUnique(Specialuseraccount.class, SpecialUserAccountSQL.GET_SPECIAL_USER_ACCOUNT, userId);
		} catch (Exception e) {
			log.error("获取专车用户账户信息时出现异常   类： " + this.getClass() + " getSpecialUserAccount()", e);
		}
		
		return null;
	}

	/**
	 * 
	 * @Title: addSpecialDepositRecord 
	 * @Description: 添加专车提现信息
	 * @param specialdepositrecord 提现信息
	 * @author YHQ 
	 * @since V2.6.3
	 * @return boolean    返回类型
	 * 
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean addSpecialDepositRecord(Specialdepositrecord specialdepositrecord) {
		
		try {
			baseDaoX.save(specialdepositrecord);
			return true;
		} catch (Exception e) {
			log.error("添加专车提现信息时出现异常   类： " + this.getClass() + " addSpecialDepositRecord()", e);
		}
		
		return false;
	}

	/**
	 * 
	 * @Title: getSpecialDepositAccount 
	 * @Description: 获取专车全部提现账户列表(启用和禁用)
	 * @param userId 用户Id
	 * @author YHQ 
	 * @since V2.6.3
	 * @return List<SpecialDepositAccount>    返回类型
	 * 
	 */
	@Override
	@Transactional(readOnly = true)
	public List<SpecialDepositAccount> getSpecialDepositAccount(String userId) {
		
		try {
			return sqlBaseDao.listSqlToCustomBean(SpecialDepositAccount.class, SpecialDepositAccountSQL.GET_ALL_SPECIAL_DEPOSIT_ACCOUNT_LIST, userId);
		} catch (Exception e) {
			log.error("获取专车全部提现账户列表(启用和禁用)时出现异常   类：" + this.getClass() + " getSpecialDepositAccount()", e);
		}
		
		return null;
	}
	
}
